import { createSlice, type PayloadAction } from "@reduxjs/toolkit";

let nextId = 2;

const slice = createSlice({
  name: "task",

  initialState: {
    raws: [{ id: 1, text: "吃饭", done: false }],
  },

  reducers: {
    add(state, { payload }: PayloadAction<string>) {
      state.raws.push({
        id: nextId++,
        text: payload,
        done: false,
      });

      // return {
      //   ...state,
      //   raws: [
      //     ...state.raws,
      //     {
      //       id: nextId++,
      //       text: payload,
      //       done: false,
      //     },
      //   ],
      // };
    },
  },
});

export const { add } = slice.actions;

export default slice.reducer;
